#include <iostream>
using namespace std;

int n,m;
string s,ret; 

int main(){
	cin >> n >> s >> m;
	int ret10 = stoi(s,NULL,n);
	while(ret10){
		if(ret10 % m >= 10){
			ret += ret10 % m - 10 + 'A';
		}
		else{
			ret += ret10 % m + '0';
		}
		ret10 /= m;
	}
	for(int i = ret.size() - 1;i >= 0;i--){
		cout << ret[i];
	}
	return 0;
}
